package com.apchernykh.rozhlasapp.ui.stations;

import com.apchernykh.ceskyrozhlas.basic.R;
import com.apchernykh.types.ApplicationModel;
import com.apchernykh.types.StationInfo;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

public class StationInfoView extends LinearLayout {

	StationInfo mStationInfo = null;

	public StationInfoView(Context iContext, AttributeSet iAttrs) {
		super(iContext, iAttrs);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		((Activity) getContext()).getLayoutInflater().inflate(
				R.layout.station_info_view, this);
	}

	public StationInfo get_stationInfo() {
		return mStationInfo;
	}

	public void set_stationInfo(StationInfo iStationInfo) {
//		if (_stationInfo != null) {
//			Log.d("set_stationInfo", _stationInfo.mShortName);
//		}
		if (iStationInfo != null) {
			this.mStationInfo = iStationInfo;
			ApplicationModel.notifyViewExpirationTime(this.mStationInfo.mExpirationTime);

			if (mStationInfo.mShortName != null) {
				TextView aShortNameText = (TextView) this
						.findViewById(R.id.tvText);
				aShortNameText.setText(mStationInfo.mShortName);
			}

			TextView aPlayingNowText = (TextView) this
					.findViewById(R.id.playingNow);
			if (mStationInfo.getPlayingNowInfo() != null
					&& mStationInfo.getPlayingNowInfo().mPrograms.size() > 0
					&& mStationInfo.getPlayingNowInfo().mPrograms.get(0).mName != null
					&& mStationInfo.getPlayingNowInfo().mPrograms.get(0).mName
							.length() > 0) {
				aPlayingNowText
						.setText(mStationInfo.getPlayingNowInfo().mPrograms
								.get(0).mName);
				aPlayingNowText.setVisibility(VISIBLE);
				aPlayingNowText.invalidate();
			} else {
				aPlayingNowText.setVisibility(GONE);
			}
		}
	}
}
